package com.zzyl.nursing.controller.member;

import com.zzyl.common.Thread.UserThreadLocal;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;

import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.dto.ReservationDto;
import com.zzyl.nursing.service.IReservationService;
import com.zzyl.serve.service.INursingProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约信息Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/reservation")
@Api(tags =  "预约信息相关接口")
public class MemberReservationController extends BaseController
{
    @Autowired
    private IReservationService reservationService;
    @GetMapping("/cancelled-count")
    @ApiOperation("查询取消预约数量")
    public AjaxResult getCancelledReservationCount() {
       int count= reservationService.getCancelledReservationCount();
        return success(count);
    }
    /**
     * 查询预约信息列表
     */

    @GetMapping("/page")
    @ApiOperation(value = "获取预约信息列表")
    public TableDataInfo<List<Reservation>> list(Reservation reservation)
    {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return getDataTable(list);
    }
    /**
     *查询每个时间段剩余预约次数
     *
     * */
    @GetMapping("/countByTime")
    @ApiOperation(value = "查询每个时间段剩余预约次数")
    public AjaxResult countByTime( @RequestParam(required = false) Long time) {
        return success();
    }
    /**
     * 新增预约信息
     *
     * */
    @PostMapping
    @ApiOperation(value = "新增预约信息")
    public AjaxResult add(@RequestBody ReservationDto reservationDto){
        reservationService.insertReservation(reservationDto);
        return success();
    }
    /**
     * 取消预约
     *
     * */
    @PutMapping("{id}/cancel")
    @ApiOperation(value = "取消预约")
    public AjaxResult cancel(@PathVariable Long id) {
        reservationService.cancelReservation(id);
        return success();
    }
}